<template>
	<view class="containe">
		<view class="top-bg">
			<!-- 顶部组件 -->
			<block v-if="userLogin">
				<view class="login-img"><image src="../../static/center_iocn.png" mode=""></image></view>
				<text class="login-title" @click="navigateTo('/pages/center/login')">点击登录</text>
			</block>
			<block class="" v-else>
				<view class="login-img" @click="updaImg"><image :src="userinfo.avatar" mode=""></image></view>
				<view class="">
					<text class="login-title">{{ userinfo.nickname }}\n</text>
					<text class="login-title">ID:{{ userinfo.username }}</text>
				</view>
				<view class="u-icon__icon" @click="cerla"><u-icon name="setting-fill"></u-icon></view>
			</block>
		</view>

		<view class="my_order">
			<view class="order-list-box">
				<!-- 我的订单 -->
				<view class="head u-flex" @click="navigateTo('/pages/user/allorder/allorder')">
					<view class="title">我的订单</view>
					<view class="more u-flex">></view>
				</view>
				<view class="item">
					<view v-for="(items, index) in myOrder.order" :key="index" @click="navigateTo(items.jumpUrl)">
						<image :src="items.img"></image>
						<view>{{ items.name }}</view>
					</view>
				</view>
				<!-- 我的订单 -->
				<view class="head u-flex"><view class="title">核心服务</view></view>
				<view class="item">
					<view v-for="(items, index) in myOrder.core" :key="index" @click="navigateTo(items.jumpUrl)">
						<image :src="items.img"></image>
						<view>{{ items.name }}</view>
					</view>
				</view>
				<!-- 我的订单 -->
				<view class="head u-flex"><view class="title">核心服务</view></view>
				<view class="item">
					<view v-for="(items, index) in myOrder.tools" :key="index" @click="navigateTo(items.jumpUrl)">
						<image :src="items.img"></image>
						<view>{{ items.name }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import myOrder from '../../common/myOrder.js';
import store from '../../store/index.js';
export default {
	data() {
		return {
			userLogin: true,
			myOrder,
			userinfo: []
		};
	},

	onShow() {
		this.$get(this.API.authInfo).then(res => {
			this.$u.vuex('vuex_user', res.data.data);
			console.log('请求', this.vuex_user);
			console.log('图片',this.vuex_user.avatar);
			
			
			})
		var me = this;
		me.userinfo = this.vuex_user;
		console.log('user', this.userinfo);
		let nickname = this.userinfo.nickname;
		//判断用户不为空显示信息
		if (nickname != '' && nickname != null && nickname != undefined) {
			me.userLogin = false;
		} else {
			me.userLogin = true;
		}
	},
	methods: {
		//路径跳转
		navigateTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		cerla() {
			uni.showModal({
				title: '提示',
				content: '是否退出登录',
				success: res => {
			  if (res.confirm) {
						this.$post(this.API.authLogout).then(res => {
							setTimeout(() => {
								this.$u.vuex('vuex_token', null);  //退出清空token
								this.$u.vuex('vuex_user', {});   //退出清空用户信息
								this.$u.route({
									type: 'reLaunch',
									url: '/pages/index/index'
								});
							}, 1000);

							uni.showToast({
								title: '退出成功'
							});
						});
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		},
		updaImg() {
			console.log('1111');
		}
	}
};
</script>

<style lang="scss" scoped>
.containe {
	width: 100vw;
	.top-bg {
		display: flex;
		align-items: center;
		height: 300rpx;
		background-color: #ffaa00;
		.login-img image {
			width: 200rpx;
			height: 200rpx;
			margin: 0 50rpx;
		}
		.login-title {
			font-size: 40rpx;
			color: #ffffff;
			padding: 0 20rpx;
		}
		.u-icon__icon {
			margin-left: 100rpx;
		}
	}
	.Login-successful {
	}

	.my_order {
		width: 100vw;
		.order-list-box {
			.head {
				display: flex;
				justify-content: space-between;
				margin: 20rpx;
				font-weight: bolder;
			}
			.item {
				display: flex;
				flex-wrap: wrap;
				padding: 0 10rpx;
				text-align: center;
				font-size: 28rpx;
				color: #555;
				box-sizing: border-box;
				border-bottom: 5rpx solid #ccc;
				& > view {
					width: 20%;
					margin-top: 28rpx;
				}
				image {
					width: 80rpx;
					height: 80rpx;
				}
			}
		}
	}
}
</style>
